package com.wltjack.springboot.controller;

import java.net.URLEncoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


import io.swagger.annotations.ApiOperation;

@Controller
@RequestMapping("/transferData")
public class TransferDataController {
	private transient final Logger log = LoggerFactory.getLogger(getClass());
	
	// http://127.0.0.1:8080/learn/transferData/commonerror
	@RequestMapping(value = "/commonerror", method = RequestMethod.GET)
    public void commonerror(HttpServletRequest request, 
    		HttpServletResponse response, Model model
    		) throws Exception {
		String msg = URLEncoder.encode("没有相应的权限","utf8"); // 中文编码
//		request.getRequestDispatcher("/app/common_error.html?code=51002&msg="+msg).forward(request, response);
		response.sendRedirect("/learn/app/common_error.html?code=51002&msg="+msg);
	}
	
	// http://127.0.0.1:8080/learn/transferData/sendRedirect
	@ApiOperation(value = "菜单入口--拦截定向入口")
    @RequestMapping(value = "/sendRedirect", method = RequestMethod.GET)
    public String sendRedirect(HttpServletRequest request, 
    		HttpServletResponse response, Model model
    		) throws Exception {
		String msg = URLEncoder.encode("没有相应的权限","utf8"); // 中文编码
    	String url = "/app/common_error.html?code=51002&msg="+msg;
    	model.addAttribute("key","123");
    	log.info("wx -- menu/sendRedirect :"+url);
        return "redirect:"+url;
    }


}
